file = open('student-list-unsorted.txt', encoding='utf-8')

students = {}

for line in file:
    line = line[0:len(line)-1]
    if line == '': 
        continue
    parts = line.split(',')
    students[parts[0]] = parts[1]


students = {key: students[key] for key in sorted(students.keys())}

out_file = open('student-list-sorted.txt', 'w', encoding='utf-8')

for key in students.keys():
    out_file.write("{},{}\n".format(key, students[key]))

out_file.close()
